package cn.com.dcsgo.validation.menu;

import cn.com.dcsgo.validation.menu.validator.MenuValidator;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 菜单校验器工厂
 *
 * @author Dcsgo
 * @since 2025/10/12 12:36
 */
@Component
public class MenuValidatorFactory {
    @Resource
    private Map<String, MenuValidator> validatorMap;

    /**
     * 获取菜单校验器
     *
     * @param menuType        菜单类型
     * @param validatorFields 校验字段及其值
     * @return 菜单校验器
     */
    public MenuValidator getMenuValidator(int menuType, Map<String, Object> validatorFields) {
        MenuValidator menuValidator = validatorMap.get(MenuType.getMenuType(menuType));
        menuValidator.prepareValidate(validatorFields);
        return menuValidator;
    }
}
